login_name = ''

# 注册
def reg():
    username = input("[注册]请输入用户名：")
    pwd = input("[注册]请输入密码：")
    phone = input("[注册]请输入手机号码：")
    from atm_1.utility import query_one
    result = query_one("select username from user_info where username = '%s'" %username)
    if result != None:
        print("用户名已存在")
    else:
        from atm_1.utility import db_operation
        db_operation("insert into user_info values ('%s','%s','%s',0)" %(username,pwd,phone))
        print("注册成功")
        from atm_1.menu import start_menu
        start_menu()

# 登录
def login():
    username = input("[登录]请输入用户名：")
    pwd = input("[登录]请输入密码：")
    from atm_1.utility import query_one
    result = query_one("select password from user_info where username = '%s'" %username)
    if result != None:
        if result[0] == pwd:
            print("登录成功")
            global login_name
            login_name = username
            from atm_1.menu import main_menu
            main_menu()
        else:
            print("密码错误")
            from atm_1.menu import start_menu
            start_menu()
    else:
        print("用户不存在")
        login()

# 修改密码
def update_pwd():
    while '1' == '1':
        new_pwd1 = input("请输入新密码：")
        new_pwd2 = input("请重复输入新密码：")
        if new_pwd1 == new_pwd2:
            break
    from atm_1.utility import db_operation
    db_operation("update user_info set password = '%s' where username = '%s'" %(new_pwd1,login_name))
    print("修改密码成功")
    from atm_1.menu import main_menu
    main_menu()